<template>
    <div>
        <table>
            <tr>
                <td>账号</td>
                <td><input type="text" v-model="data.name"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" v-model="data.pwd"></td>
            </tr>
            <tr>
                <td><input type="button" value="登录" @click="Login"></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref} from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
import { uselogerStore } from '@/stores/loger';

const user=uselogerStore();

const rount=useRouter()

const data=ref({
    name:"",
    pwd:""
})


const Login=()=>{
    axios.get("https://localhost:7087/api/User/Login",{params:data.value}).then(res=>{
        if(res.data.id==-1){
            alert('用户名错误')
            return;
        }
        if(res.data.id==-2){
            alert('密码错误')
            return;
        }
        if(res.data.id>0){
            user.user.username=data.value.name;
            user.user.islogin=true;
            alert('登录成功')
            rount.push({path:'/ShowView'})
            return;
        }
    })
}

</script>

<style scoped>

</style>